<template>
  <div>
    <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange" @sendUserSearch="getSearch" :searchData="userSearchData" :isHaveExport="false" :isHaveAdd="false">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" v-loading="loading" stripe header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.8%">
          <el-table-column label="头像" align="center" min-width="80">
            <template slot-scope="scope">
              <img class="pic_pay user_img" :src="$fnc.getImgUrl(scope.row.shop_avatar)" />
            </template>
          </el-table-column>

          <el-table-column label="商户信息" min-width="80">
            <template slot-scope="scope">
              <div class="user_table">
                <span>商户昵称：&nbsp;</span>
                <small>{{ scope.row.sid_nickname || "---" }}</small>
                <br />
                <span>商户账号：&nbsp;</span>
                <small>{{ scope.row.sid_username || "---" }}</small>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="商品图片" min-width="80">
            <template slot-scope="scope">
              <router-link :to="'/index/shop/addproduct?id=' + scope.row.pid">
                <img class="pic_pay" :src="$fnc.getImgUrl(scope.row.piclink)" />
              </router-link>
            </template>
          </el-table-column>
          <el-table-column label="商品信息" min-width="200">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>商品标题：</span>
                  <span>{{ scope.row.title }}</span>
                </div>
                <div v-if="scope.row.label && scope.row.label.length > 0">
                  <span>商品标签：</span>
                  <el-tag v-for="(label, l) in scope.row.label" style="margin-right:5px;color:#ffffff;margin-left:0" size="mini" :key="l"
                      effect="dark">
                    {{ label }}</el-tag>
                </div>
                <div v-if="scope.row.is_check_promotion == 2">
                  <span style="font-weight:bold">驳回原因：</span>
                  <span>{{ scope.row.reason_promotion }}</span>
                  <br />
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="促销信息" min-width="220">
            <template slot-scope="scope">
              <div class="tab_div">
                <div v-if="scope.row.types_promotion == 7">
                  <span style="font-weight:bold">限时特惠：</span>
                  <span>{{ scope.row.discount_rob }}折</span>
                  <br />
                  <span style="font-weight:bold">折扣价格：</span>
                  <span>{{ scope.row.limited_price }}元</span>
                  <br />
                  <span style="font-weight:bold">限购数量：</span>
                  <span>{{ scope.row.discount_limit }}</span>
                  <br />
                  <span style="font-weight:bold">优惠时间：</span>
                  <span>{{ scope.row.rob_time_begin | getTimeFormat }}---{{
                      scope.row.rob_time_end | getTimeFormat
                    }}</span>
                  <br />
                </div>
                <div v-if="scope.row.types_promotion == 2">
                  <span style="font-weight:bold">积分兑换：</span>
                  <span>{{ scope.row.score_rob }}</span>
                  <br />
                  <span style="font-weight:bold">积分分类：</span>
                  <span>{{ scope.row.integral_cate_cn }}</span>
                </div>
                <div v-if="scope.row.types_promotion == 4">
                  <span style="font-weight:bold">拼团人数：</span>
                  <span>{{ scope.row.group_people }}</span>
                  <br />
                  <span style="font-weight:bold">拼团折扣：</span>
                  <span>{{ scope.row.group_discount | keepTwoNum }}折</span>
                  <br />
                  <span style="font-weight:bold">拼团时间：</span>
                  <span>{{ scope.row.group_time }}小时</span>
                  <br />
                  <span style="font-weight:bold">团长免单：</span>
                  <span>{{ scope.row.group_face == 0 ? "否" : "是" }}</span>
                  <br />
                </div>
                <div v-if="scope.row.types_promotion == 8">
                  <span style="font-weight:bold">赠送公排权值：</span>
                  <span>{{ scope.row.platoon | keepTwoNum }}</span>
                </div>
                <div v-if="scope.row.types_promotion == 3">
                  <span style="font-weight:bold">砍价次数：</span>
                  <span>{{ scope.row.bargain_number }}次</span>
                  <br />
                  <span style="font-weight:bold">单次最低砍价价格：</span>
                  <span>{{ $fnc.toFixedZ(scope.row.bargain_begin) }}元</span>
                  <br />
                  <span style="font-weight:bold">单次最高砍价价格：</span>
                  <span>{{ $fnc.toFixedZ(scope.row.bargain_end) }}元</span>
                  <br />
                  <span style="font-weight:bold">最多累计砍价金额：</span>
                  <span>{{ $fnc.toFixedZ(scope.row.bargain_price) }}元</span>
                  <br />
                  <span style="font-weight:bold">时间期限（小时）：</span>
                  <span>{{ scope.row.bargain_time }}小时</span>
                  <br />
                </div>
                <div v-if="scope.row.types_promotion == 6">
                  <span style="font-weight:bold">定金：</span>
                  <span>{{ scope.row.down_pay }}元</span>
                  <br />
                  <span style="font-weight:bold">发货期：</span>
                  <span>{{ scope.row.delivery_date | getTimeFormat }}</span>
                  <br />
                  <div class="presale">
                    <span style>单数</span>
                    <span>预售价</span>
                    <div v-for="(item, k) in toParst(scope.row.ladder)" :key="k">
                      <span>{{ item.ladder_num }}单</span>
                      <span>{{ item.ladder_money }}元</span>
                    </div>
                  </div>
                </div>
                <div v-if="scope.row.types_promotion == 18">
                  <span style="font-weight:bold">竞拍方式：</span>
                  <span>{{
                    scope.row.auction_types == 0 ? "提价拍" : "降价拍"
                  }}</span>
                  <br />
                  <span style="font-weight:bold">起拍价：</span>
                  <span>{{ $fnc.toFixedZ(scope.row.starting_price) }}元</span>
                  <br />

                  <span style="font-weight:bold">流拍价：</span>
                  <span>{{ $fnc.toFixedZ(scope.row.auction_price) }}元</span>
                  <br />

                  <span style="font-weight:bold">加减幅度：</span>
                  <span>{{ $fnc.toFixedZ(scope.row.auction_amplitude) }} ~
                    {{ $fnc.toFixedZ(scope.row.auction_amplitude_max) }}元</span>
                  <br />

                  <span style="font-weight:bold">保证金：</span>
                  <span>{{ $fnc.toFixedZ(scope.row.auction_margin) }}元</span>
                  <br />

                  <span style="font-weight:bold">开始时间：</span>
                  <span>{{ scope.row.auction_open_time | getTimeFormat }}</span>
                  <br />

                  <span style="font-weight:bold">结束时间：</span>
                  <span>{{ scope.row.auction_end_time }}分钟</span>
                  <br />

                  <span style="font-weight:bold">下一轮开始时间：</span>
                  <span>{{ scope.row.auction_next_time }}分钟</span>
                  <br />
                </div>

                <div v-if="scope.row.types_promotion == 19">
                  <span style="font-weight:bold">拼购价格：</span>
                  <span>{{ $fnc.toFixedZ(scope.row.group_buy_price) }}</span>
                  <br />
                  <span style="font-weight:bold">拼购分类：</span>
                  <span>{{ scope.row.group_buy_cate }}</span>
                </div>

                <div v-if="
                    scope.row.types_promotion == 10 ||
                      scope.row.types_promotion == 11
                  ">
                  <span style="font-weight:bold">核销次数 ：</span>
                  <span>{{ Number(scope.row.write_number) }}</span>
                  <br />
                  <span style="font-weight:bold">每次核销奖励核销人金额：</span>
                  <span>{{ $fnc.toFixedZ(scope.row.write_reward) }}</span>
                </div>

                <div v-if="scope.row.types_promotion == 24">
                  <span style="font-weight:bold">邮费：</span>
                  <span>{{ $fnc.toFixedZ(scope.row.zeromail) }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="促销类型" min-width="80">
            <template slot-scope="scope">{{ scope.row.types_promotion_cn }}
            </template>
          </el-table-column>
          <el-table-column label="促销状态" min-width="100">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.is_check_promotion == 1" type="success" effect="dark">申请中</el-tag>
              <el-tag v-else-if="scope.row.is_check_promotion == 2" type="warning" effect="dark">已通过</el-tag>
              <el-tag v-else-if="scope.row.is_check_promotion == 3" type="warning" effect="dark">驳回
              </el-tag>
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center" min-width="140">
            <template slot-scope="scope">
              <el-button :loading="$store.state.isLoading" v-if="scope.row.is_check == 0" size="mini" type="primary" @click="
                  showDio(
                    scope.row.id,
                    scope.row.is_check,
                    scope.row.remark,
                    scope.row.types
                  )
                ">编辑</el-button>
              <el-button :loading="$store.state.isLoading" size="mini" type="primary" :disabled="scope.row.is_check_promotion == 1 ? false : true"
                  @click="check_shop(scope.row.id)">审核</el-button>
              <el-button :loading="$store.state.isLoading" size="mini" type="danger" @click="delSupplierComplaint(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>
    <el-dialog :close-on-click-modal="false" title="审核" :modal-append-to-body="false" :visible.sync="check_show" class="tl size_13" width="800px">
      <el-form :model="check_form" ref="data" class="mar_top" label-width="120px">
        <el-form-item label="审核" prop="remark">
          <el-col :span="12">
            <el-radio-group v-model="check_form.is_check">
              <el-radio label="0">通过</el-radio>
              <el-radio label="1">驳回</el-radio>
            </el-radio-group>
          </el-col>
        </el-form-item>

        <el-form-item label="驳回理由" prop="remark" v-if="check_form.is_check == 1">
          <el-col :span="12">
            <el-input placeholder="请输入驳回理由" type="textarea" v-model="check_form.reason_promotion" clearable></el-input>
          </el-col>
        </el-form-item>

        <el-form-item>
          <el-button :loading="$store.state.isLoading" type="primary" size="small" @click="cofirm_check()">确认</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog :close-on-click-modal="false" title="编辑促销" :modal-append-to-body="false" :visible.sync="show" class="tl size_13" width="800px">
      <el-form :model="data" ref="data" class="mar_top" label-width="100px">
        <el-form-item label="审核" label-width="150px" prop="remark">
          <el-col :span="16">
            <el-radio-group v-model="data.is_check">
              <el-radio label="0">通过</el-radio>
              <el-radio label="1">驳回</el-radio>
            </el-radio-group>
          </el-col>
        </el-form-item>
        <el-form-item label="备注" label-width="150px" prop="remark">
          <el-col :span="16">
            <el-input placeholder type="textarea" disabled v-model="data.remark" style="width:400px" clearable></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="管理员备注" label-width="150px" prop="remark">
          <el-col :span="16">
            <el-input placeholder="请输入管理员备注" type="textarea" v-model="data.admin_remark" style="width:400px" clearable></el-input>
          </el-col>
        </el-form-item>

        <!-- <div class="mar_bottom_15">
                    <span class="sizeColor size_13 sp_style"></span>
                    <el-button :loading='$store.state.isLoading'
                        size="medium"
                        type="primary"
                        @click.prevent="addUpdate">确定</el-button>
        </div>-->
      </el-form>
      <el-form ref="form" v-if="data.is_check == 0">
        <el-form-item label="活动场景：" label-width="150px">
          <el-col :span="16">
            <el-select v-model="activity_form.types" size="small" clearable placeholder="请选择" style="width: 150px" @change="sel_event">
              <el-option v-for="(item, k) in activity_option" :key="item" :label="item" :value="k"></el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <template v-if="activity_form.types == '3'">
          <el-form-item label="砍价次数：" label-width="150px">
            <el-col :span="16">
              <el-input size="small" clearable type="number" v-model="activity_form.bargain_number" placeholder="请输入砍价次数" style="width:200px">
              </el-input>
              <span style="padding-left:10px;"></span>
            </el-col>
          </el-form-item>
          <el-form-item label="单次最低砍价价格：" label-width="150px">
            <el-col :span="16">
              <el-input size="small" clearable type="number" v-Int v-model="activity_form.bargain_begin" placeholder="请输入最低砍价价格" style="width:200px">
              </el-input>
              <span style="padding-left:10px;"></span>
            </el-col>
          </el-form-item>
          <el-form-item label="单次最高砍价价格：" label-width="150px">
            <el-col :span="16">
              <el-input size="small" clearable type="number" v-Int v-model="activity_form.bargain_end" placeholder="请输入最高砍价价格" style="width:200px">
              </el-input>
              <span style="padding-left:10px;"></span>
            </el-col>
          </el-form-item>
            <el-form-item label="最多累计砍价金额：" label-width="150px">
            <el-col :span="16">
              <el-input size="small" clearable type="number" v-model="activity_form.bargain_price" placeholder="请输入最多累计砍价金额" style="width:200px">
              </el-input>
              <span style="padding-left:10px;"></span>
            </el-col>
          </el-form-item>
          <el-form-item label="时间期限（小时）：" label-width="150px">
            <el-col :span="16">
              <el-input size="small" clearable type="number" v-model="activity_form.bargain_time" placeholder="请输入砍价时间期限" style="width:200px">
              </el-input>
              <span style="padding-left:10px;"></span>
            </el-col>
          </el-form-item>
        </template>
        <template v-if="activity_form.types == '4'">
          <el-form-item label="拼团人数：" label-width="150px">
            <el-col :span="16">
              <el-input size="small" clearable type="number" v-model="activity_form.group_people" placeholder="请输入拼团人数" style="width:200px">
              </el-input>
              <span style="padding-left:10px;"></span>
            </el-col>
          </el-form-item>
          <el-form-item label="拼团折扣：" label-width="150px">
            <el-col :span="16">
              <el-input size="small" clearable type="number" v-model="activity_form.group_discount" placeholder="请输入拼团折扣" style="width: 200px">
              </el-input>
              <span style="padding-left:10px;">折</span>
            </el-col>
          </el-form-item>
          <el-form-item label="拼团时间：" label-width="150px">
            <el-col :span="16">
              <el-input size="small" clearable type="number" v-model="activity_form.group_time" placeholder="请输入拼团时间" style="width: 200px"></el-input>
              <span style="padding-left:10px;">小时</span>
            </el-col>
          </el-form-item>
          <el-form-item label="团长免单：" label-width="150px">
            <el-col :span="16">
              <el-switch class="zdySwith" :width="82" v-model="activity_form.group_face" active-color="#1aad19" inactive-color="#ffffff"
                  active-text="是" inactive-text="否" active-value="1" inactive-value="0"></el-switch>
            </el-col>
          </el-form-item>
        </template>
        <el-form-item label="消耗积分：" label-width="150px" v-show="activity_form.types == '2'">
          <el-col :span="16">
            <el-input size="small" clearable v-model="activity_form.score_rob" placeholder="请输入消耗积分" style="width:200px"></el-input>
            <span style="padding-left:10px;"></span>
          </el-col>
        </el-form-item>
        <el-form-item label="商品折扣：" label-width="150px" v-show="activity_form.types == '7'">
          <el-col :span="16">
            <el-input size="small" clearable v-model="activity_form.discount_rob" placeholder="请输入商品折扣" style="width: 200px"></el-input>
            <span style="padding-left:10px;">折</span>
          </el-col>
        </el-form-item>
        <el-form-item label="商品数量：" label-width="150px" v-show="activity_form.types == '7'">
          <el-col :span="16">
            <el-input size="small" clearable v-model="activity_form.discount_limit" placeholder="请输入活动商品数量" style="width:200px"></el-input>
            <span style="padding-left:10px;"></span>
          </el-col>
        </el-form-item>
        <el-form-item label="选择时区：" label-width="150px" v-show="activity_form.types == '7'">
          <el-col :span="16">
            <el-select v-model="activity_form.time_id" size="small" clearable placeholder="请选择" style="width: 500px">
              <el-option v-for="(item, i) in time_option" :key="i" :label="item.time_str" :value="item.id"></el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="公排权值：" label-width="150px" v-show="activity_form.types == '8'">
          <el-col :span="16">
            <el-input size="small" clearable v-model="activity_form.platoon" placeholder="请输入赠送的公排权值" style="width:200px"></el-input>
            <span style="padding-left:10px;"></span>
          </el-col>
        </el-form-item>
        <template v-if="activity_form.types == '6'">
          <el-form-item label="定金：" label-width="150px">
            <el-col :span="16">
              <el-input size="small" clearable type="number" v-model="activity_form.down_pay" placeholder="请输入定金" style="width:200px"></el-input>
              <span style="padding-left:10px;"></span>
            </el-col>
          </el-form-item>
          <el-form-item label="发货期：" label-width="150px">
            <el-col :span="16">
              <el-date-picker v-model="delivery" type="date" size="small" placeholder="选择日期"></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="预售阶梯：" label-width="150px">
            <el-col :span="16" v-for="(item, k) in presale" :key="k">
              <el-col :span="8">
                <el-input size="small" clearable type="number" v-model="item.ladder_num" placeholder="请输入单数" style="width:100% "></el-input>
              </el-col>
              <el-col :span="2">--</el-col>
              <el-col :span="8">
                <el-input size="small" clearable type="number" v-model="item.ladder_money" placeholder="请输入预售价"
                    @blur="lose_laddermoney(k, item.ladder_money)" style="width:100% "></el-input>
              </el-col>
              <el-col :span="4" v-show="k + 1 == presale.length ? true : false">
                <el-button :loading="$store.state.isLoading" size="small" type="primary" style="margin-left:15px" @click="add_presale">增加</el-button>
              </el-col>
            </el-col>
          </el-form-item>
        </template>

        <template v-if="activity_form.types == '10' || activity_form.types == '11'">
          <el-form-item label="核销次数：" label-width="150px">
            <el-col :span="16">
              <el-input size="small" clearable type="number" v-model="activity_form.write_number" placeholder="请输入核销次数" style="width:240px">
              </el-input>
              <span style="padding-left:10px;">次</span>
            </el-col>
          </el-form-item>

          <el-form-item label="核销金额：" label-width="150px">
            <el-col :span="20">
              <el-input size="small" clearable type="number" v-model="activity_form.write_reward" placeholder="请输入每次核销奖励核销人金额" style="width:240px">
              </el-input>
              <span style="padding-left:10px;">元</span>
            </el-col>
          </el-form-item>
        </template>
      </el-form>
      <div style="display:flex;    justify-content: center;">
        <el-button :loading="$store.state.isLoading" type="primary" size="small" @click="add_activity_submit()">添 加</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { supplierpromotionSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data () {
    return {
      check_form: {},
      check_show: false,
      userSearchData: supplierpromotionSearchData,
      delivery: "",
      presale: [
        {
          ladder_num: "",
          ladder_money: "",
          finish_per: 0
        }
      ],
      time_option: [], //时区
      activity_option: {}, //活动场景
      activity_form: {}, //活动信息
      list: [],
      pageSize: 10,
      currentPage: 1,
      loading: false,
      show: false,
      data: {
        remark: "",
        is_check: "0"
      },
      searchAll: {}
    };
  },
  created () {
    this.getNewsAll();
    this.get_activity_option();
  },
  methods: {
    toParst (JSONarr) {
      console.log(JSONarr);
      if (JSONarr) {
        return JSON.parse(JSONarr);
      }
    },
    cofirm_check () {
      if (this.check_form.is_check != 0 && this.check_form.is_check != 1) {
        this.$fnc.alertError("请审核");
        return;
      }
      var params = {
        id: this.check_form.id
      };
      var methods = "";
      if (this.check_form.is_check == 0) {
        methods = "approved_supplier_activity";
      } else if (this.check_form.is_check == 1) {
        params.reason_promotion = this.check_form.reason_promotion;
        methods = "pass_supplier_activity";
      }
      this.$api.getSupplier[methods](params).then(res => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess(res.data.result);
          this.check_show = false;

          this.getNewsAll(this.searchAll);
        } else {
          this.$fnc.alertError(res.data.result);
        }
      });
    },
    check_shop (id) {
      this.check_form = {
        id: id
      };
      this.check_show = true;
    },
    lose_laddermoney (l, money) {
      if (Number(money) <= this.activity_form.down_pay) {
        this.$fnc.alertError("预售价不能小于定金");
        this.presale[l].ladder_money = this.activity_form.down_pay;
      }
    },
    add_presale () {
      var obj = {
        ladder_num: "",
        ladder_money: "",
        finish_per: 0
      };
      this.presale.push(obj);
    },
    add_activity_submit () {
      this.show = false;
      if (this.data.is_check == 0) {
        //通过
        this.$api.getSupplier.approvedSupplierPromotion(this.data).then(res => {
          if (res.data.code == 200) {
            var params = this.activity_form;
            if (this.activity_form.types == 6) {
              var flag = false;
              this.presale.forEach(item => {
                if (Number(item.ladder_money) <= this.activity_form.down_pay) {
                  this.$fnc.alertError("预售价不能小于定金");
                  flag = true;
                }
              });
              if (flag) {
                return;
              }
              params.ladder = JSON.stringify(this.presale);
            }
            this.$api.getShops.add_event(params).then(res => {
              if (res.data.code == 200) {
                this.$fnc.alertSuccess("添加成功");
                this.getNewsAll(this.searchAll);
              } else {
                this.$fnc.alertError(res.data.result);
              }
            });
          } else {
            this.$fnc.alertError(res.data.code_desc, res.data.result);
          }
        });
      } else if (this.data.is_check == 1) {
        //驳回
        this.$api.getSupplier.setSupplierPromotion(this.data).then(res => {
          this.getNewsAll(this.searchAll);
          if (res.data.code == 200) {
            this.$fnc.alertSuccess({ text: res.data.code_desc });
          } else {
            this.$fnc.alertError(res.data.code_desc, res.data.result);
          }
        });
      }
    },
    sel_event (val) {
      if (val == 4) {
        this.$set(this.activity_form, "group_face", "0");
      }
      if (val == 7) {
        this.$api.getShops.get_limittime({}).then(res => {
          if (res.data.code == 200) {
            this.time_option = res.data.result;
            this.time_option.forEach(item => {
              var str1 = this.getTimeFormat(item.begin_time);
              var str2 = this.getTimeFormat(item.end_time);
              item.time_str = str1 + "---" + str2;
            });
          }
        });
      }
      for (var k in this.activity_option) {
        val == k ? (this.activity = this.activity_option[k]) : "";
      }
    },
    get_activity_option () {
      this.$api.getShops.get_activitylist({}).then(res => {
        if (res.data.code == 200) {
          this.activity_option = res.data.result;
        }
      });
    },
    getSearch (obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    handleSizeChange (val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange (val) {
      this.$router.push(this.$route.path + "?page=" + val);
    },
    getNewsAll () {
      this.loading = true;
      var params = this.searchAll;
      params.page = this.$route.query.page || 1;
      params.page_size = this.pageSize;

      this.currentPage = Number(this.$route.query.page) || 1;
      // this.$api.getSupplier.getSupplierPromotion(params).then(res => {
      //   if (res.data.code == 200) {
      //     this.list = res.data.result;
      //   }
      //   this.loading = false;
      // });
      params.types_promotion = 1;
      this.$api.getShops.getShopsList(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    showDio (id, is_check, remark, types) {
      this.data.id = id;
      this.data.is_check = is_check;
      this.data.remark = remark;
      this.$set(this.data, "admin_remark", "");
      this.activity_form = {};
      this.activity_form.id = id;
      this.show = true;

      for (const key in this.activity_option) {
        if (this.activity_option.hasOwnProperty(key)) {
          if (this.activity_option[key] == types) {
            this.$set(this.activity_form, "types", key);
            // this.activity_form.types = key;
          }
        }
      }
    },

    addUpdate () {
      this.show = false;
      if (this.data.is_check == 0) {
        //通过
        this.$api.getSupplier.approvedSupplierPromotion(this.data).then(res => {
          this.getNewsAll(this.searchAll);
          if (res.data.code == 200) {
            this.$fnc.alertSuccess({ text: res.data.code_desc });
          } else {
            this.$fnc.alertError(res.data.code_desc, res.data.result);
          }
        });
      } else if (this.data.is_check == 1) {
        //驳回
        this.$api.getSupplier.setSupplierPromotion(this.data).then(res => {
          this.getNewsAll(this.searchAll);
          if (res.data.code == 200) {
            this.$fnc.alertSuccess({ text: res.data.code_desc });
          } else {
            this.$fnc.alertError(res.data.code_desc, res.data.result);
          }
        });
      }
    },
    delSupplierComplaint (id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "如果删除，商品将重新变成普通商品",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var data = { id: id };
          this.$api.getSupplier.cancel_supplier_activity(data).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", res.data.result, "success");
              this.getNewsAll();
            } else {
              this.$swal("删除失败！", res.data.result, "success");
            }
          });
        }
      });
    }
  },
  watch: {
    $route () {
      this.getNewsAll();
    },
    delivery (val) {
      var time = val.getTime();
      this.activity_form.delivery_date = this.$fnc.phptime(time);
    }
  }
};
</script>
